import { config } from '@vimi/utils-tool'
import { BASE_URL } from '../plugins/constant'

import * as commonUtils from './common'
import { getUserUtils } from './user'

// 重置 baseUrl
config.baseUrl = BASE_URL

const install = function (Vue, { store = {}, serviceName = 'credit', plugins = {} } = {}) {
  if (install.installed) return

  const utils = Object.create(null)
  const addUtils = obj => Object.keys(obj).forEach(key => (utils[key] = obj[key]))

  addUtils(commonUtils)
  addUtils(getUserUtils(store))
  addUtils(plugins)

  Vue.prototype.$utils = utils
  Vue.prototype.$serviceName = serviceName
}

export default {
  install,
}
